package com.desksoft.ecommerce.util.html.element.format;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.desksoft.ecommerce.util.html.PageXml;
import com.desksoft.ecommerce.util.html.element.PageElement;
import com.desksoft.ecommerce.util.html.element.format.colname.ColName;

/**
 * 表格显示格式化
 * @author Administrator
 *
 */
public class ViewFormat extends PageElement implements Serializable {

	protected PageXml pageXml;
	
	protected List<DisplayFormat> displayFormatList;
	
	protected List<ColName> colNameList;
   
	public ViewFormat(Element element, PageXml pageXml) {
		super();
		 
		this.pageXml = pageXml;
		displayFormatList = parse(element.elements("display-format"));
		colNameList = parseColName(element.element("col-name"));
	}
	
	/**
	 * 解析格式化元素
	 */
	public List<DisplayFormat> parse(List<Element> elementL){
		List<DisplayFormat> list = new ArrayList<DisplayFormat>();
		for (Element elmt : elementL){
			list.add(new DisplayFormat(elmt, pageXml));
		}
		return list;
	}
	
	/**
	 * 解析列名显示元素
	 */
	public List<ColName> parseColName(Element elmtColName){
		
		if (elmtColName == null){
			return new ArrayList<ColName>();
		}
		
		List<Element> elmtL = elmtColName.elements("column");
		List<ColName> colNameL = new ArrayList<ColName>(elmtL.size());
		
		for (Element elmt : elmtL){
			String name = elmt.attributeValue("name"),
					display = elmt.attributeValue("display");
			colNameL.add(new ColName(name, display));
		}
		
		return colNameL;
	}

	public List<DisplayFormat> getDisplayFormatList() {
		return displayFormatList;
	}

	public void setDisplayFormatList(List<DisplayFormat> displayFormatList) {
		this.displayFormatList = displayFormatList;
	}

	public List<ColName> getColNameList() {
		return colNameList;
	}

	public void setColNameList(List<ColName> colNameList) {
		this.colNameList = colNameList;
	}
	
}
